#音转文模型接口
import sys
from pathlib import Path
# 确保导入路径正确
sys.path.insert(0, str(Path(__file__).parent / "third_party/Matcha-TTS"))
from cosyvoice.cli.cosyvoice import CosyVoice2

MODEL_PATH = 'pretrained_models/CosyVoice2-0.5B'

class AudioModel:
    def __init__(self):
        self.cosyvoice = CosyVoice2(
            MODEL_PATH,
            load_jit=False,
            load_trt=False,
            fp16=True #半精度 提高速度
        )

    def generate_stream(self, text, prompt_text, audio):
        # 流式生成
        return self.cosyvoice.inference_zero_shot(
            text, 
            prompt_text, 
            audio, 
            stream=True,
            speed=1.0
        )
    
    def generate_full(self, text, prompt_text, audio):
        return self.cosyvoice.inference_zero_shot(
            text, 
            prompt_text, 
            audio, 
            stream=False,
            speed=1.0
        )

    
